﻿using System;
using System.Collections.Generic;

namespace AiFrame.InterfaceLib.Data.Patterns
{
    public class ObservableList<T>: BaseObservableList<T>, IObservableList<T>
    {

        public new void Add(T item)
        {
            base.Add(item);
            this.OnItemAdded(item);
        }

        public new void Sort(IComparer<T> comparer)
        {
            base.Sort(comparer);
            this.OnItemsReset();
        }

        public void Replace(T obj)
        {
            this.OnItemReplace(obj);
        }

        public new void Clear()
        {
            base.Clear();
            this.OnItemsReset();
        }

        public new void Insert(int index, T item)
        {
            base.Insert(index, item);
            this.OnItemAdded(item);
        }

        public new bool Remove(T item)
        {
            int index = this.IndexOf(item);

            bool result = base.Remove(item);
            this.OnItemRemoved(item, index);

            return result;
        }

        public new void RemoveAt(int index)
        {
            T item = this[index];

            base.RemoveAt(index);
            this.OnItemRemoved(item, index);
        }

        public void Sort(Comparison<T> comparison)
        {
            base.Sort(comparison);
            this.OnItemsReset();
        }
    }
}
